package org.acghub.mtdb.demo.bean;

/**
* xmlgen自动生成，不要修改此文件！！！
*/
public final class Pet extends org.acghub.mtdb.core.TBean {
	private Integer id;

	private String name;

	private Integer age;

	private Byte gender;

	public Pet(org.acghub.mtdb.core.TBean _xp_, String _vn_) {
		super(_xp_, _vn_);
	}

	public Pet() {
		this(null, null);
	}

	@Override
	protected void onConstructor() {
		this.id = 0;
		this.name = "";
		this.age = 0;
		this.gender = 0;
	}

	public Integer getId() {
		this._verify_unsafe_("getId", true);
		return this.id;
	}
	public String getName() {
		this._verify_unsafe_("getName", true);
		return this.name;
	}
	public Integer getAge() {
		this._verify_unsafe_("getAge", true);
		return this.age;
	}
	public Byte getGender() {
		this._verify_unsafe_("getGender", true);
		return this.gender;
	}
	public Pet setId(Integer v) {
		java.lang.Runnable _verify_ = this._verify_unsafe_("setId", false);
		if (java.util.Objects.equals(this.id, v)) {
			return this;
		}
		org.acghub.mtdb.core.Logs.simple(this, "id", this.id, _verify_);
		this.id = v;
		return this;
	}
	public Pet setName(String v) {
		java.lang.Runnable _verify_ = this._verify_unsafe_("setName", false);
		if (java.util.Objects.equals(this.name, v)) {
			return this;
		}
		org.acghub.mtdb.core.Logs.simple(this, "name", this.name, _verify_);
		this.name = v;
		return this;
	}
	public Pet setAge(Integer v) {
		java.lang.Runnable _verify_ = this._verify_unsafe_("setAge", false);
		if (java.util.Objects.equals(this.age, v)) {
			return this;
		}
		org.acghub.mtdb.core.Logs.simple(this, "age", this.age, _verify_);
		this.age = v;
		return this;
	}
	public Pet setGender(Byte v) {
		java.lang.Runnable _verify_ = this._verify_unsafe_("setGender", false);
		if (java.util.Objects.equals(this.gender, v)) {
			return this;
		}
		org.acghub.mtdb.core.Logs.simple(this, "gender", this.gender, _verify_);
		this.gender = v;
		return this;
	}
	@Override
	public org.bson.Document marshal(org.bson.Document writer) {
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.id)) {
			writer.append("id", this.id);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.name)) {
			writer.append("name", this.name);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.age)) {
			writer.append("age", this.age);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.gender)) {
			writer.append("gender", this.gender);
		}
		return writer;
	}

	@Override
	public void unmarshal(org.bson.Document reader) {
		if (reader.containsKey("id")) {
			this.id = reader.get("id", Integer.class);
		}
		if (reader.containsKey("name")) {
			this.name = reader.get("name", String.class);
		}
		if (reader.containsKey("age")) {
			this.age = reader.get("age", Integer.class);
		}
		if (reader.containsKey("gender")) {
			this.gender = reader.get("gender", Number.class).byteValue();
		}
	}

	@Override
	public com.alibaba.fastjson2.JSONObject marshal(com.alibaba.fastjson2.JSONObject writer) {
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.id)) {
			writer.put("id", this.id);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.name)) {
			writer.put("name", this.name);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.age)) {
			writer.put("age", this.age);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.gender)) {
			writer.put("gender", this.gender);
		}
		return writer;
	}

	@Override
	public void unmarshal(com.alibaba.fastjson2.JSONObject reader) {
		if (reader.containsKey("id")) {
			this.id = reader.getInteger("id");
		}
		if (reader.containsKey("name")) {
			this.name = reader.getString("name");
		}
		if (reader.containsKey("age")) {
			this.age = reader.getInteger("age");
		}
		if (reader.containsKey("gender")) {
			this.gender = reader.getByte("gender");
		}
	}

	@Override
	public int hashCode() {
		int hash = this.getObjId().intValue();
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.id)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.id);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.name)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.name);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.age)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.age);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.gender)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.gender);
		}
		return hash;
	}

	@Override
	public boolean equals(Object o) {
		if (null == o || !getClass().equals(o.getClass())) { return false; }
		if (this == o) { return true; }
		Pet that = (Pet) o;
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.id, that.id)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.name, that.name)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.age, that.age)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.gender, that.gender)) { return false; }
		return true;
	}
	@Override
	public String toString() {
		return new java.util.StringJoiner(", ", "Pet[", "]")
				.add("id=" + id)
				.add("name=" + name)
				.add("age=" + age)
				.add("gender=" + gender)
				.toString();
	}
}

